﻿Public Class XRAYPOS
    Dim connect As CONDB = CONDB.NewConnection()
    Dim selectsequen As Boolean = False
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub XRAYPOS_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objSelectDataMasposxray As New MASPOSXRAY
        SelectDatagridMasposxray()

        DesignForm(Me)
        DesignGrid(MASPOSXRAYGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMasposxray()
        Dim objSelectDatamasposxray As New MASPOSXRAY
        Dim masposxrayData As DataTable
        masposxrayData = connect.GetTable(objSelectDatamasposxray.selectMasposxray_)
        MASPOSXRAYGrid.PrimaryGrid.DataSource = masposxrayData
    End Sub

    Private Sub MASPOSXRAYGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASPOSXRAYGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        PXRYIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID กลุ่ม").Value()
        PXRYNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อกลุ่ม").Value()
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            MasPosxrayStatusChk.Checked = True
        Else
            MasPosxrayStatusChk.Checked = False
        End If

        addMasposxray.Enabled = False
    End Sub

    Private Sub addMasposxray_Click(sender As Object, e As EventArgs) Handles addMasposxray.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If PXRYNAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New MASPOSXRAY
                    objInsertData.PXRYNAME_ = PXRYNAMETxt.Text
                    objInsertData.STATUS_ = MasPosxrayStatusChk.Checked
                    objInsertData.insertMasposxrayData()

                    SelectDatagridMasposxray()

                    PXRYNAMETxt.Text = ""
                    MasPosxrayStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasposxray_Click(sender As Object, e As EventArgs) Handles editMasposxray.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If PXRYIDTxt.Text.ToString.Length > 0 And PXRYNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลกลุ่มดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New MASPOSXRAY
                        objEditData.PXRYID_ = PXRYIDTxt.Text
                        objEditData.PXRYNAME_ = PXRYNAMETxt.Text
                        objEditData.STATUS_ = MasPosxrayStatusChk.Checked
                        objEditData.editMasposxrayData()

                        SelectDatagridMasposxray()

                        PXRYNAMETxt.Text = ""
                        MasPosxrayStatusChk.Checked = False
                        PXRYIDTxt.Text = ""
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
                addMasposxray.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masposxray")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masposxray")
        nextform.ShowDialog()
    End Sub
End Class